/**
 * @author LKQ
 * @date 2022/2/25 10:33
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.complexNumberMultiply("1+-1i", "1+-1i"));
    }
    public String complexNumberMultiply(String num1, String num2) {
        int[] n1 = get(num1), n2 = get(num2);
        int a = n1[0], b = n1[1], c = n2[0] , d = n2[1];
        StringBuffer sb = new StringBuffer();
        int resA = a * c - b * d;
        sb.append("" + resA + '+');
        int resB = a * d + b * c;
        sb.append("" + resB + 'i');
        return sb.toString();

    }
    public int[] get(String num) {
        int a = 0, b = 0;
        for (int i = 0; i < num.length(); i++) {
            if (num.charAt(i) == '+') {
                a = Integer.parseInt(num.substring(0, i));
                b = Integer.parseInt(num.substring(i+1, num.length() - 1));
                break;
            }
        }
        return new int[]{a, b};
    }
}
